**********REPLICATION SYNTAX FOR **********
*Engelhardt, Andrew M. & Cindy D. Kam. A Racial Reckoning? Racial Attitudes in the Wake of the Murder of George Floyd*
**********PSRM**********
*Data sourced from Gallup GPSS Polling Series, acquired by license from Gallup*

*Gallup MIP series
set more off
set scheme s1mono
log using "C:\Users\kamcd\Dropbox\CDK WORK\BLM IAT paper\Writing\PSRM\Final Submission\Replication Files\2_Gallup MIP\Gallup_MIP_PSRM.log"

cd "C:/Users/kamcd/Dropbox/CDK WORK/BLM IAT paper/Gallup GPSS Polling Series/"
use "2017 Key Indicators.dta", clear
append using "2018 Key Indicators.dta"
append using "2019 Key Indicators.dta"
append using "2020 Demos.dta", force
append using "2021 Demos.dta", force

cd "C:\Users\kamcd\Dropbox\CDK WORK\BLM IAT paper\Writing\PSRM\Final Submission\Replication Files\2_Gallup MIP"

/*Survey weight*/
gen allweight = weight
replace allweight = wtfctr if wtfctr~=.
svyset [pw=allweight]

/*Time variable for graphing*/
gen allyear = year
replace allyear = yr if yr==2020|yr==2021
gen allyearmonth = allyear+month*.01

egen yrmonthgraph = group(allyearmonth)
lab def yrmonthgraph 1"Jan 2017" 7"July 2017" 13"Jan 2018" 19"July 2018" 25"Jan 2019" 31 "July 2019" 37"Jan 2020" 43 "July 2020" 49"Jan 2021" 55"Jul 2021"
lab val yrmonthgraph yrmonthgraph 

*Monthly dummies
forval v=1/55 {
recode yrmonthgraph (`v'=1)(else=0), gen(month`v')
}
lab var month1 "Jan-2017"
lab var month2 "Feb-2017"
lab var month3 "Mar-2017"
lab var month4 "Apr-2017"
lab var month5 "May-2017"
lab var month6 "Jun-2017"
lab var month7 "Jul-2017"
lab var month8 "Aug-2017"
lab var month9 "Sep-2017"
lab var month10 "Oct-2017"
lab var month11 "Nov-2017"
lab var month12 "Dec-2017"
lab var month13 "Jan-2018"
lab var month14 "Feb-2018"
lab var month15 "Mar-2018"
lab var month16 "Apr-2018"
lab var month17 "May-2018"
lab var month18 "Jun-2018"
lab var month19 "Jul-2018"
lab var month20 "Aug-2018"
lab var month21 "Sep-2018"
lab var month22 "Oct-2018"
lab var month23 "Nov-2018"
lab var month24 "Dec-2018"
lab var month25 "Jan-2019"
lab var month26 "Feb-2019"
lab var month27 "Mar-2019"
lab var month28 "Apr-2019"
lab var month29 "May-2019"
lab var month30 "Jun-2019"
lab var month31 "Jul-2019"
lab var month32 "Aug-2019"
lab var month33 "Sep-2019"
lab var month34 "Oct-2019"
lab var month35 "Nov-2019"
lab var month36 "Dec-2019"
lab var month37 "Jan-2020"
lab var month38 "Feb-2020"
lab var month39 "Mar-2020"
lab var month40 "Apr-2020"
lab var month41 "May-2020"
lab var month42 "Jun-2020"
lab var month43 "Jul-2020"
lab var month44 "Aug-2020"
lab var month45 "Sep-2020"
lab var month46 "Oct-2020"
lab var month47 "Nov-2020"
lab var month48 "Dec-2020"
lab var month49 "Jan-2021"
lab var month50 "Feb-2021"
lab var month51 "Mar-2021"
lab var month52 "Apr-2021"
lab var month53 "May-2021"
lab var month54 "Jun-2021"
lab var month55 "Jul-2021"

tostring yrmody, gen(stringdate)
gen nicedate = date(stringdate, "YMD")
format nicedate %td
egen IWday = group(nicedate)
*histogram IWday, freq title("Number of IWs per day") width(1) xtitle("Days since Jan 2017")
//given lumpiness and sparse coverage, may want weekly or probably monthly data

svy, subpop(month41): tab mip1
//text discusses covid (code 47), government (23), economy (6), and race (25)
svy, subpop(month42): tab mip1
//text discusses covid (code 47), race (25), and government (23)

/*Most Important Problem, first mention*/
//Race Relations is coded 25
//Crime/Violence is coded 14
//Police bruality is coded 79

forval v=1/3 {
recode kimip`v' (25=1)(0/24 26/99=0)(else=.), gen(kimip`v'race)
recode mip`v' (25=1)(0/24 26/99=0)(else=.), gen(mip`v'race)
gen racemip`v' = .
replace racemip`v' = kimip`v'race if kimip`v'race~=.
replace racemip`v' = mip`v'race if mip`v'race ~=.

recode kimip`v' (14=1)(0/13 15/99=0)(else=.), gen(kimip`v'crime)
recode mip`v' (14=1)(0/13 15/99=0)(else=.), gen(mip`v'crime)
gen crimemip`v' = .
replace crimemip`v' = kimip`v'crime if kimip`v'crime~=. 
replace crimemip`v' = mip`v'crime if mip`v'crime~=.
}


forval v=1/3 {
recode kimip`v' (79=1)(0/78 80/99=0)(else=.), gen(kimip`v'policebrut)
recode mip`v' (79=1)(0/78 80/99=0)(else=.), gen(mip`v'policebrut)
gen policebrut`v' = .
replace policebrut`v' = kimip`v'policebrut if kimip`v'policebrut~=. 
replace policebrut`v' = mip`v'policebrut if mip`v'policebrut~=.
}


//by race
gen White = .
replace White =1 if ki_race ==1
replace White =1 if racewh==1

gen Black= .
replace Black=1 if ki_race ==2
replace Black =1 if racebk==1

gen BlackW=Black
replace BlackW=0 if White==1


//by Party
gen GOP = .
replace GOP = 1 if kiparty2 ==1|partyr==1
gen Dem= .
replace Dem = 1 if kiparty2 ==2|partyr==3

gen pid3cat = Dem
replace pid3cat = -1 if GOP==1
replace pid3cat = 0 if kiparty2==3|partyr==2
lab def pid3cat -1 "GOP" 0 "Pure Ind" 1 "Dem"
lab val pid3cat pid3cat

gen WDem = .
replace WDem = 1 if Dem ==1 & White==1
gen WGOP = .
replace WGOP = 1 if GOP ==1 & White==1
gen WInd = .
replace WInd = 1 if pid3cat==0 & White==1


//number of IWs per month 
preserve
egen IWpermonth=group(yrmonthgraph)
sum IWpermonth, det
gen constant = 1
collapse (count) constant, by(IWpermonth)
sum constant, det
restore

/*Graph with race MIP by month*/
preserve
collapse racemip1 crimemip1 policebrut1 [pw=allweight], by(yrmonthgraph)
twoway (scatter racemip1 yrmonthgraph, mcolor(black)) (lowess racemip1 yrmonthgraph if yrmonthgraph<42, lcolor(black)) ///
(lowess racemip1 yrmonthgraph if yrmonthgraph >=42, lcolor(black)) , ///
xlabel(1(6)49, val alternate labsize(small)) xtitle(" ") ytitle("Race Relations as Most Important Problem") ///
title("Full Sample") legend(off) name(raceMIPbymonth, replace) xline(42, lcolor(red))

twoway (scatter racemip1 yrmonthgraph, mcolor(black)) (lowess racemip1 yrmonthgraph if yrmonthgraph<42, lcolor(black)) ///
(lowess racemip1 yrmonthgraph if yrmonthgraph >=42, lcolor(black)) , ///
xlabel(1(6)49, val alternate labsize(small)) xtitle(" ") title("Race Relations as MIP") ///
t2title("Gallup Poll, 2017-2021") legend(off) note("Lowess smoothing") name(raceMIPbymonthA, replace) xline(42, lcolor(red))

twoway (scatter crimemip1 yrmonthgraph, mcolor(black)) (lowess crimemip1 yrmonthgraph if yrmonthgraph<42, lcolor(black)) ///
(lowess crimemip1 yrmonthgraph if yrmonthgraph >=42, lcolor(black)) , ///
xlabel(1(6)49, val alternate labsize(small)) xtitle(" ") title("Crime/Violence as MIP") ///
t2title("Gallup Poll, 2017-2021") legend(off) note("Lowess smoothing") name(crimeMIPbymonth, replace) xline(42, lcolor(red))

twoway (scatter policebrut1 yrmonthgraph, mcolor(black)) (lowess policebrut1 yrmonthgraph if yrmonthgraph<42, lcolor(black)) ///
(lowess policebrut1 yrmonthgraph if yrmonthgraph >=42, lcolor(black)) , ///
xlabel(1(6)49, val alternate labsize(small)) xtitle(" ") title("Police Brutality as MIP") ///
t2title("Gallup Poll, 2017-2021") legend(off) note("Lowess smoothing") name(policebrutMIPbymonth, replace) xline(42, lcolor(red))

twoway (lowess racemip1 yrmonthgraph if yrmonthgraph<38, lcolor(black))(lowess racemip1 yrmonthgraph if yrmonthgraph>37, lcolor(black)) , ///
xlabel(1(6)49, val alternate labsize(small)) xtitle(" ") ytitle("Race Relations as MIP") title("Breakpoint Feb 2020") legend(off) ///
xline(42, lcolor(red)) name("Break37", replace)

twoway (lowess racemip1 yrmonthgraph if yrmonthgraph<39, lcolor(black))(lowess racemip1 yrmonthgraph if yrmonthgraph>38, lcolor(black)) , ///
xlabel(1(6)49, val alternate labsize(small)) xtitle(" ") ytitle("Race Relations as MIP") title("Breakpoint Mar 2020") legend(off) ///
xline(42, lcolor(red)) name("Break38", replace)

twoway (lowess racemip1 yrmonthgraph if yrmonthgraph<40, lcolor(black))(lowess racemip1 yrmonthgraph if yrmonthgraph>39, lcolor(black)) , ///
xlabel(1(6)49, val alternate labsize(small)) xtitle(" ") ytitle("Race Relations as MIP") title("Breakpoint Apr 2020") legend(off) ///
xline(42, lcolor(red)) name("Break39", replace)

twoway (lowess racemip1 yrmonthgraph if yrmonthgraph<41, lcolor(black))(lowess racemip1 yrmonthgraph if yrmonthgraph>40, lcolor(black)) , ///
xlabel(1(6)49, val alternate labsize(small)) xtitle(" ") ytitle("Race Relations as MIP") title("Breakpoint May 2020") legend(off) ///
xline(42, lcolor(red)) name("Break40", replace)

twoway (lowess racemip1 yrmonthgraph if yrmonthgraph<42, lcolor(black))(lowess racemip1 yrmonthgraph if yrmonthgraph>41, lcolor(black)) , ///
xlabel(1(6)49, val alternate labsize(small)) xtitle(" ") ytitle("Race Relations as MIP") title("Breakpoint Jun 2020") legend(off) ///
xline(42, lcolor(red)) name("Break41", replace)

twoway (lowess racemip1 yrmonthgraph if yrmonthgraph<43, lcolor(black))(lowess racemip1 yrmonthgraph if yrmonthgraph>42, lcolor(black)) , ///
xlabel(1(6)49, val alternate labsize(small)) xtitle(" ") ytitle("Race Relations as MIP") title("Breakpoint Jul 2020") legend(off) ///
xline(42, lcolor(red)) name("Break42", replace)

twoway (lowess racemip1 yrmonthgraph if yrmonthgraph<44, lcolor(black))(lowess racemip1 yrmonthgraph if yrmonthgraph>43, lcolor(black)) , ///
xlabel(1(6)49, val alternate labsize(small)) xtitle(" ") ytitle("Race Relations as MIP") title("Breakpoint Aug 2020") legend(off) ///
xline(42, lcolor(red)) name("Break43", replace)

twoway (lowess racemip1 yrmonthgraph if yrmonthgraph<45, lcolor(black))(lowess racemip1 yrmonthgraph if yrmonthgraph>44, lcolor(black)) , ///
xlabel(1(6)49, val alternate labsize(small)) xtitle(" ") ytitle("Race Relations as MIP") title("Breakpoint Sept 2020") legend(off) ///
xline(42, lcolor(red)) name("Break44", replace)

twoway (lowess racemip1 yrmonthgraph if yrmonthgraph<46, lcolor(black))(lowess racemip1 yrmonthgraph if yrmonthgraph>45, lcolor(black)) , ///
xlabel(1(6)49, val alternate labsize(small)) xtitle(" ") ytitle("Race Relations as MIP") title("Breakpoint Oct 2020") legend(off) ///
xline(42, lcolor(red)) name("Break45", replace)

restore 

//BY RACE
preserve
collapse racemip1 [pw=allweight], by(yrmonthgraph BlackW)
twoway (scatter racemip1 yrmonthgraph if BlackW==1, mcolor(black)) (lowess racemip1 yrmonthgraph if yrmonthgraph<42 & BlackW==1, lcolor(black)) ///
(lowess racemip1 yrmonthgraph if yrmonthgraph >=42 & BlackW==1, lcolor(black)) , ///
xlabel(1(6)49, val alternate labsize(small)) xtitle(" ") ytitle("Race Relations as Most Important Problem") ///
legend(off) name(MIPbymonthB, replace) ///
title("Among Blacks") xline(42, lcolor(red))
twoway (scatter racemip1 yrmonthgraph if BlackW==0, mcolor(black)) (lowess racemip1 yrmonthgraph if yrmonthgraph<42 & BlackW==0, lcolor(black)) ///
(lowess racemip1 yrmonthgraph if yrmonthgraph >=42 & BlackW==0, lcolor(black)) , ///
xlabel(1(6)49, val alternate labsize(small)) xtitle(" ") ytitle("Race Relations as Most Important Problem") ///
legend(off) name(MIPbymonthW, replace) ///
title("Among Whites") xline(42, lcolor(red))
restore 

//by Party AMONG WHITES
preserve
collapse racemip1 [pw=allweight] if White==1, by(yrmonthgraph pid3cat)
twoway (scatter racemip1 yrmonthgraph if pid3cat==1, mcolor(black)) (lowess racemip1 yrmonthgraph if yrmonthgraph<42 & pid3cat==1, lcolor(blue)) ///
(lowess racemip1 yrmonthgraph if yrmonthgraph >=42 & pid3cat==1, lcolor(blue)) , ///
xlabel(1(6)49, val alternate labsize(small)) xtitle(" ") ytitle("Race Relations as Most Important Problem") ///
legend(off) name(MIPbymonthWD, replace) ///
title("Among White Democrats") xline(42, lcolor(red))
twoway (scatter racemip1 yrmonthgraph if pid3cat==0, mcolor(black)) (lowess racemip1 yrmonthgraph if yrmonthgraph<42 & pid3cat==0, lcolor(grey)) ///
(lowess racemip1 yrmonthgraph if yrmonthgraph >=42 & pid3cat==0, lcolor(grey)) , ///
xlabel(1(6)49, val alternate labsize(small)) xtitle(" ") ytitle("Race Relations as Most Important Problem") ///
legend(off) name(MIPbymonthWI, replace) ///
title("Among White Independents") xline(42, lcolor(red))
twoway (scatter racemip1 yrmonthgraph if pid3cat==-1, mcolor(black)) (lowess racemip1 yrmonthgraph if yrmonthgraph<42 & pid3cat==-1, lcolor(red)) ///
(lowess racemip1 yrmonthgraph if yrmonthgraph >=42 & pid3cat==-1, lcolor(red)) , ///
xlabel(1(6)49, val alternate labsize(small)) xtitle(" ") ytitle("Race Relations as Most Important Problem") ///
legend(off) name(MIPbymonthWR, replace) ///
title("Among White Republicans") xline(42, lcolor(red))
restore 

//Statistical tests
recode yrmonthgraph (0/41=0 "Pre GF")(42/100=1 "Post GF")(else=.), gen(prepostmonthly)
lab var prepostmonthly "Post GF, June 2020-May 2021"
svyset [pw=allweight]
svy: reg racemip1 prepostmonthly
est store prepostmonthly
svy: reg racemip1 month42-month55
est store postmonthly
est table prepostmonthly postmonthly, b(%9.2f) star(.1 .05 .01) stats(N)

coefplot prepostmonthly postmonthly, xline(0, lcolor(red)) keep( prepostmonthly month42 month43 month44 month45 month46 month47 month48 month49 month50 month51 month52 month53 month54 month55) plotlabels("Pre-Post" "Monthly Indicators") title("Full Sample") name(All_temporal, replace)

//number of black Democrats, Republicans and Independents 
//not survey weighted: just to provide raw counts for FN
tab pid3cat if Black==1

//by racial group
svyset [pw=allweight]
svy, subpop(White): reg racemip1 prepostmonthly
est store prepostmonthlyW
svy, subpop(White): reg racemip1 month42-month55
est store postmonthlyW
est table prepostmonthlyW postmonthlyW, b(%9.2f) star(.1 .05 .01) stats(N)
coefplot prepostmonthlyW postmonthlyW, xline(0, lcolor(red)) keep( prepostmonthly month42 month43 month44 month45 month46 month47 month48 month49 month50 month51 month52 month53 month54 month55) plotlabels("Pre-Post" "Monthly Indicators") title("Whites") name(Whites_temporal, replace)

svy, subpop(Black): reg racemip1 prepostmonthly
est store prepostmonthlyB
svy, subpop(Black): reg racemip1 month42-month55
est store postmonthlyB
est table prepostmonthlyB postmonthlyB, b(%9.2f) star(.1 .05 .01) stats(N)

coefplot prepostmonthlyB postmonthlyB, xline(0, lcolor(red)) keep( prepostmonthly month42 month43 month44 month45 month46 month47 month48 month49 month50 month51 month52 month53 month54 month55) plotlabels("Pre-Post" "Monthly Indicators") title("Blacks") name(Blacks_temporal, replace)

suest postmonthlyW postmonthlyB
test [postmonthlyW]month42=[postmonthlyB]month42
/*0.04*/


//by party among Whites
svy, subpop(WDem): reg racemip1 prepostmonthly
est store prepostmonthlyWD
svy, subpop(WDem): reg racemip1 month42-month55
est store postmonthlyWD
est table prepostmonthlyWD postmonthlyWD, b(%9.2f) star(.1 .05 .01) stats(N)
coefplot prepostmonthlyWD postmonthlyWD, xline(0, lcolor(red)) keep( prepostmonthly month42 month43 month44 month45 month46 month47 month48 month49 month50 month51 month52 month53 month54 month55) plotlabels("Pre-Post" "Monthly Indicators") title("White Democrats") name(WD_temporal, replace)

svy, subpop(WInd): reg racemip1 prepostmonthly
est store prepostmonthlyWI
svy, subpop(WInd): reg racemip1 month42-month55
est store postmonthlyWI
est table prepostmonthlyWI postmonthlyWI, b(%9.2f) star(.1 .05 .01) stats(N)
coefplot prepostmonthlyWI postmonthlyWI, xline(0, lcolor(red)) keep( prepostmonthly month42 month43 month44 month45 month46 month47 month48 month49 month50 month51 month52 month53 month54 month55) plotlabels("Pre-Post" "Monthly Indicators") title("White Independents") name(WI_temporal, replace)

svy, subpop(WGOP): reg racemip1 prepostmonthly
est store prepostmonthlyWR
svy, subpop(WGOP): reg racemip1 month42-month55
est store postmonthlyWR
est table prepostmonthlyWR postmonthlyWR, b(%9.2f) star(.1 .05 .01) stats(N)
coefplot prepostmonthlyWR postmonthlyWR, xline(0, lcolor(red)) keep( prepostmonthly month42 month43 month44 month45 month46 month47 month48 month49 month50 month51 month52 month53 month54 month55) plotlabels("Pre-Post" "Monthly Indicators") title("White Republicans") name(WR_temporal, replace)

suest postmonthlyWD postmonthlyWR 
test [postmonthlyWD]month42=[postmonthlyWR]month42
/*0.003*/

**********FIGURE 2 IN MANUSCRIPT**********
graph combine raceMIPbymonth MIPbymonthW MIPbymonthB MIPbymonthWR MIPbymonthWI MIPbymonthWD, ycommon common note("Lowess smoothing. Gallup Poll 2017-2021") row(2) altshrink 
graph export Fig2.tif, replace

/*APPENDIX FIGURE A2*/
graph combine All_temporal Whites_temporal Blacks_temporal WR_temporal WI_temporal WD_temporal , ycommon common row(2) altshrink 
graph export FigA2.tif, replace

/*APPENDIX FIGURE A3*/
graph combine Break37 Break38 Break39 Break40 Break41 Break42 Break43 Break44 Break45, row(3) name(monthlyplacebo, replace) ycommon altshrink
graph export FigA3.tif, replace

/*APPENDIX FIGURE A4*/
graph combine raceMIPbymonthA crimeMIPbymonth policebrutMIPbymonth, row(1) ysize(3) xsize(6) ycommon altshrink
graph export FigA4.tif, replace

log close
